import { ICON_LAYOUT, ICON_PAINT } from "./conf";

export const ICON_MODES = ["draw_icon"];

export function generateIconLayer({ map, mode, features }) {
	features.forEach((feature) => {
		feature.properties = {
			...ICON_LAYOUT,
			...ICON_PAINT,
			...feature.properties,
		};
	});

	const iconLayer = {
		id: `${mode}-${features[0].id}-icon`,
		type: "symbol",
		source: {
			type: "geojson",
			data: {
				type: "FeatureCollection",
				features,
			},
		},
		layout: {
			"icon-image": ["get", "iconPath"],
			"icon-size": ["get", "size"],
			"icon-offset": ["get", "offset"],
		},
		paint: {
			"icon-opacity": ["get", "opacity"],
			"icon-halo-color": ["get", "haloColor"],
			"icon-halo-width": ["get", "haloWidth"],
		},
	};

	map.addLayer(iconLayer);

	return [iconLayer.id];
}

export function isIconMode(mode) {
	return ICON_MODES.includes(mode);
}
